

/* 
 *  Copyright (c) 2011—2013 Panguso.com. All rights reserved. 
 *  File Name:  emails.java                                      
 *  File Contents Outline :  发送邮件                  
 *  File  Create Date:   2012年7月30日
 *  File Version#: Revision#: #1                  
 *  File  Latest Modify Date : 2013年1月16日
 *  File Author :  bachuan@panguso.com
 */

package cn.edu.thu.log.util;

import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class emails {


	public static boolean emailExecute(String from,String to,String subject,String messageText,String password){   
			boolean bool=true;
			try{
			String mailserver="smtp.qq.com";
			Properties props=new Properties();
			props.put("mail.smtp.host", mailserver);
			props.put("mail.smtp.auth", "true");
			Session sess=Session.getInstance(props);
			sess.setDebug(true);
			MimeMessage message=new MimeMessage(sess);
			
			InternetAddress from_mail=new InternetAddress(from);
			message.setFrom(from_mail);
			
			InternetAddress to_meil=new InternetAddress(to);
			message.setRecipient(Message.RecipientType.TO,to_meil);
			message.setSubject(subject);
			message.setText(messageText);
			message.setSentDate(new Date());
			
			
			message.saveChanges();
			Transport transport=sess.getTransport("smtp");
			transport.connect(mailserver,from, password);
			transport.sendMessage(message, message.getAllRecipients());
			transport.close();
			
			
			bool=true;			//�ʼ����ͳɹ��� ����true
			} catch (Exception e) {
				// TODO Auto-generated catch block
				
				e.printStackTrace();
				bool=false;    //�ʼ�����ʧ���� ����false
				
			}
			return bool;
		}
   
}
